Shader "Depth/xray"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _rayColor("Base Color", Color) = (0, 1, 1, 1)
    }
    SubShader
    {
Pass
        {
            Tags { "RenderType"="Transparent" "Queue"="Transparent" }
            Blend SrcAlpha One
            ZTest Greater
            ZWrite Off
            CULL Back

            CGPROGRAM
            #include "UnityCG.cginc"
            #pragma vertex vert
            #pragma fragment frag

            struct appdata
            {
                float4 pos : POSITION;
                float4 normal : NORMAL;
            };

            struct v2f
            {
                float4 pos : SV_POSITION;
                float4 color : COLOR;
            };

            fixed4 _rayColor;

            v2f vert (appdata vertex)
            {
                v2f o;

                o.pos = UnityObjectToClipPos(vertex.pos);

                float3 viewDir = ObjSpaceViewDir(o.pos);
                viewDir = normalize(viewDir);
                float3 normal = normalize(vertex.normal);
                float rim = 1 - dot(normal, viewDir);
                o.color = _rayColor * rim;

                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                return i.color;
            }
            ENDCG
        }
        Pass
        {
            Tags { "RenderType"="Opaque" }
            ZTest LEqual
            ZWrite on

            CGPROGRAM
            #include "UnityCG.cginc"
            #pragma vertex vert
            #pragma fragment frag

              struct appdata
            {
                float4 pos : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 pos : SV_POSITION;
            };

            
            sampler2D _MainTex;
            float4 _MainTex_ST;

             v2f vert (appdata v)
            {
                v2f o;
                o.pos = UnityObjectToClipPos(v.pos);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);

                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col = tex2D(_MainTex, i.uv);
                return col;
            }
            ENDCG
        }

        
    }
}
